using Microsoft.AspNetCore.Mvc;
using OnWork.Admin.BLL.System;
using OnWork.Admin.System;
using OnWork.Admin.Util;
using System.ComponentModel.DataAnnotations;

namespace LRSMESX.WebApi.Controllers.admin_sys
{
    /// <summary>
    /// 系统用户表
    /// 创建者：chenchao
    /// 电子邮箱：chenhome@qq.com
    /// 创建时间：2024-08-15 16:09
    /// </summary>
    public class SysUserController : BaseSystemController
    {
        private ILogger<SysUserController> logger;

        private SysUserBLL bll;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="loggerIn"></param>
        /// <param name="bLL"></param>
        public SysUserController(ILogger<SysUserController> loggerIn, SysUserBLL bLL)
        {
            logger = loggerIn;
            bll = bLL;
        }

        /// <summary>
        /// 分页查询
        /// </summary>
        /// <param name="search">搜索条件</param>
        /// <param name="pageindex">页数</param>
        /// <param name="pagesize">每页条数</param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ReturnModel> PageListAsync(string search, int pageindex, int pagesize)
        {
            PagetionModel pagetion = new PagetionModel { Pagenumber = pageindex, PageSize = pagesize };

            var templist = await bll.GetPageListAsync(search, pagetion);
            return new ReturnModel { Code = 200, Data = templist, Ok = true, Msg = "查询成功!" };
        }

        /// <summary>
        /// 新增
        /// </summary>
        /// <param name="obj">参数</param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ReturnModel> EntityAddAsync([FromBody] SysUserDto obj)
        {
            return await bll.EntityAddAsync(obj);
        }

        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="obj">参数</param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ReturnModel> EntityEditAsync([FromBody] SysUserDto obj)
        {
            return await bll.EntityEditAsync(obj);
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="ids">id集合（xxxx,xxxx,xxxx）</param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ReturnModel> EntityDeleteAsync([Required] string ids)
        {
            return await bll.EntityDeleteAsync(ids);
        }
    }
}